Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: save_extra_cmds only works with single string #375

Merged
merged 5 commits into from
Sep 16, 2024

Conversation

cameronr
Copy link
Collaborator

@cameronr cameronr commented Sep 12, 2024

I found this while implementing the quickfix saving idea in #173

Lib.run_hook_cmds returns a table of tables (one for reach hook cmd that was run). In save_extra_cmds, vim.fn.writefile expects a table strings and if any of those strings contain newlines, they're translated into nul characters. That means that there was no way to return more than one line from a save_extra_cmds hook function.

To fix, we combine the results across all save_extra_cmds hooks into a single table and we now support a save_extra_cmds hook returning either a string (possibly with newlines) or table. If a hook returns a string then any newlines will be used to split the string into individual line entries in the table passed to vim.fn.writefile. If a hook returns a table, then each of the values of the table will be added to the table passed to vim.fn.writefile (the same newline splitting will also happen)

Also fix typo in auto_restore_last_session config name #377

`Lib.run_hook_cmds` returns a table of tables (one for reach hook cmd
that was run). In `save_extra_cmds`, `vim.fn.writefile` expects a table
strings and if any of those strings contain newlines, they're
translated into nul characters. That means that there was no way to
return more than one line from a `save_extra_cmds` hook function.

To fix, we combine the results across all `save_extra_cmds` hooks and we
now support a `save_extra_cmds` hook returning either a string (possibly
with newlines) or table. If a hook returns a string then any newlines
will be used to split the string into individual line entries in the
table passed to `vim.fn.writefile`. If a hook returns a table, then each
of the values of the table will be added to the table passed to
`vim.fn.writefile` (the same newline splitting will also happen)
Copy link

@rbmarliere rbmarliere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Tested-by: Ricardo B. Marliere [email protected]

cameronr and others added 3 commits September 15, 2024 09:03
The code will already load it on demand as needed. If someone uses
Telescope, they'll already have it specified in their config so we don't
need to list it as a dependency
@cameronr cameronr merged commit 51e2693 into rmagatti:main Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants